<?php

namespace App\Http\Controllers\School;

use App\Http\Resources\School\UserMealStatisticsResource;
use App\Models\User;
use Illuminate\Http\Request;

/**
 * Class MealStatisticsController
 * @package App\Http\Controllers\School
 * 老师用餐统计
 */
class MealStatisticsController extends BaseController
{
    /**
     * @param Request $request
     * @return mixed
     */
    public function index(Request $request)
    {
        $users = User::query()
            ->orderBy('name', 'asc')
            ->with('role:id,name', 'bookOrderStatistics')
            ->where('school_id', \Auth::user()->school_id)
            ->where('status', User::ACTIVE)
            ->select(['id', 'name', 'role_id', 'phone'])
            ->nameLike($request->name)
            ->phoneLike($request->phone);
        if ($request->type === 'export') {
            $users = $users->get();
        } else {
            $users = $users->paginate($request->size);
        }
        return UserMealStatisticsResource::collection($users);
    }
}
